classdef NoInvGain < Cell
    properties
    end
    
    methods
        function this = NoInvGain(g)
            this.Name = 'NoInvGain';
            this.Gain = g;
            this.calcCell(g);
            this.ImagePath = 'Stages Schematics/NoInvGain.png';
        end
        
        function calcCell(obj,g)
            %abs(G)=1+R2/R1
            obj.Gain=abs(g);
            
            if (obj.Gain<=10)
                R1=10e3; % Default and initial value.
            else
                R1=1e3;
            end
            
            R2=(obj.Gain-1)*R1;
            
            while (~obj.rangopiola(R2))
                if obj.rangopiola(R1)
                    R1=10*R1;
                else
                    R1=R1/10;
                    break;
                end
            R2=(obj.Gain-1)*R1;
            end
            
            obj.Resists(1)=R1;
            obj.Resists(2)=R2;
            
            obj.error = ~(obj.rangopiola(R1)&&obj.rangopiola(R2));
            
        end
        
        function componentChange(obj,component,value)        
            %abs(G)=1+R2/R1
            switch component
                case 1
                    obj.Resists(1)=value;
                    obj.Resists(2)=(obj.Gain-1)*value;
                case 2
                    obj.Resists(1)=value/(obj.Gain-1);
                    obj.Resists(2)=value;
            end
        end
        
        function ret=rangopiola(obj,R)
            ret = (~isempty(R))&&(isreal(R))&&(R>=100)&&(R<=1e6);
        end
    end
end